import request from '@/utils/request'

// 班级管理相关接口
export const classApi = {
  // 获取班级列表
  getClassList: (params) => request({
    url: '/api/class/list',
    method: 'get',
    params
  }),
  
  // 创建班级
  createClass: (data) => request({
    url: '/api/class/create',
    method: 'post',
    data
  }),
  
  // 更新班级信息
  updateClass: (id, data) => request({
    url: `/api/class/${id}`,
    method: 'put',
    data
  }),
  
  // 删除班级
  deleteClass: (id) => request({
    url: `/api/class/${id}`,
    method: 'delete'
  }),
  
  // 获取班级详情
  getClassDetail: (id) => request({
    url: `/api/class/${id}`,
    method: 'get'
  }),

  // 导入学生
  importStudents: (classId, data) => request({
    url: `/api/class/${classId}/import-students`,
    method: 'post',
    data
  })
}

// 课程管理相关接口
export const courseApi = {
  // 获取课程列表
  getCourseList: (params) => request({
    url: '/api/course/list',
    method: 'get',
    params
  }),
  
  // 创建课程
  createCourse: (data) => request({
    url: '/api/course/create',
    method: 'post',
    data
  }),
  
  // 更新课程信息
  updateCourse: (id, data) => request({
    url: `/api/course/${id}`,
    method: 'put',
    data
  }),
  
  // 删除课程
  deleteCourse: (id) => request({
    url: `/api/course/${id}`,
    method: 'delete'
  }),
  
  // 获取课程详情
  getCourseDetail: (id) => request({
    url: `/api/course/${id}`,
    method: 'get'
  })
}

// 项目管理相关接口
export const projectApi = {
  // 获取项目列表
  getProjectList: (params) => request({
    url: '/api/project/list',
    method: 'get',
    params
  }),
  
  // 创建项目
  createProject: (data) => request({
    url: '/api/project/create',
    method: 'post',
    data
  }),
  
  // 更新项目信息
  updateProject: (id, data) => request({
    url: `/api/project/${id}`,
    method: 'put',
    data
  }),
  
  // 删除项目
  deleteProject: (id) => request({
    url: `/api/project/${id}`,
    method: 'delete'
  }),
  
  // 获取项目详情
  getProjectDetail: (id) => request({
    url: `/api/project/${id}`,
    method: 'get'
  })
}

// 成就管理相关接口
export const achievementApi = {
  // 获取成就列表
  getAchievementList: (params) => request({
    url: '/api/achievement/list',
    method: 'get',
    params
  }),
  
  // 创建成就
  createAchievement: (data) => request({
    url: '/api/achievement/create',
    method: 'post',
    data
  }),
  
  // 更新成就信息
  updateAchievement: (id, data) => request({
    url: `/api/achievement/${id}`,
    method: 'put',
    data
  }),
  
  // 删除成就
  deleteAchievement: (id) => request({
    url: `/api/achievement/${id}`,
    method: 'delete'
  }),
  
  // 获取成就详情
  getAchievementDetail: (id) => request({
    url: `/api/achievement/${id}`,
    method: 'get'
  }),

  // 审核成就
  reviewAchievement: (id, data) => request({
    url: `/api/achievement/${id}/review`,
    method: 'post',
    data
  })
}

// 用户相关接口
export const userApi = {
  // 登录
  login: (data) => request({
    url: '/api/user/login',
    method: 'post',
    data
  }),
  
  // 注册
  register: (data) => request({
    url: '/api/user/register',
    method: 'post',
    data
  }),
  
  // 获取用户信息
  getUserInfo: () => request({
    url: '/api/user/info',
    method: 'get'
  }),
  
  // 更新用户信息
  updateUserInfo: (data) => request({
    url: '/api/user/info',
    method: 'put',
    data
  }),
  
  // 修改密码
  changePassword: (data) => request({
    url: '/api/user/password',
    method: 'put',
    data
  }),
  
  // 重置密码
  resetPassword: (data) => request({
    url: '/api/user/reset-password',
    method: 'post',
    data
  })
}

// 公共接口
export const commonApi = {
  // 上传文件
  uploadFile: (data) => request({
    url: '/api/common/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }),
  
  // 获取枚举值
  getEnums: (type) => request({
    url: '/api/common/enums',
    method: 'get',
    params: { type }
  })
}

// OJ相关接口
export const ojApi = {
  // 获取题目列表
  getProblemList: (params) => request({
    url: '/api/oj/problems',
    method: 'get',
    params
  }),
  
  // 获取题目详情
  getProblemDetail: (id) => request({
    url: `/api/oj/problems/${id}`,
    method: 'get'
  }),
  
  // 提交代码
  submitCode: (data) => request({
    url: '/api/oj/submit',
    method: 'post',
    data
  }),
  
  // 获取提交历史
  getSubmissionHistory: (params) => request({
    url: '/api/oj/submissions',
    method: 'get',
    params
  }),
  
  // 获取提交详情
  getSubmissionDetail: (id) => request({
    url: `/api/oj/submissions/${id}`,
    method: 'get'
  }),
  
  // 下载提交报告
  downloadReport: (id) => request({
    url: `/api/oj/submissions/${id}/report`,
    method: 'get',
    responseType: 'blob'
  }),
  
  // 下载测试用例结果
  downloadTestcases: (id) => request({
    url: `/api/oj/submissions/${id}/testcases`,
    method: 'get',
    responseType: 'blob'
  })
} 